package edu.nepu.flink.api.sql;

import edu.nepu.flink.api.bean.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import static org.apache.flink.table.api.Expressions.$;

/**
 * @Date 2024/3/5 21:39
 * @Created by chenshuaijun
 */
public class ApplicationDemo {

    public static void main(String[] args) {

        /**
         * 需要解决的问题是
         * 同样还是用户的一组点击事件，我们可以查询出某个用户（例如Alice）点击的url列表，
         * 也可以统计出每个用户累计的点击次数
         */

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


        DataStreamSource<WaterSensor> sensorDS = env.fromElements(
                new WaterSensor("s1", 1L, 1),
                new WaterSensor("s1", 2L, 2),
                new WaterSensor("s2", 2L, 2),
                new WaterSensor("s3", 3L, 3),
                new WaterSensor("s3", 4L, 4)
        );

        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        Table table = tableEnv.fromDataStream(sensorDS);

        tableEnv.createTemporaryView("sensors",table);


    }
}
